# encoding:utf-8

from app.models.base import db
import os
from app import create_app
from app.models.user import Employee, Role
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, Employee=Employee)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)


@manager.command
def create_roles():
    roles = [u'董事长', u'总经理',u'副总经理', u'普通员工']
    for r in roles:
        role = Role(name=r)
        db.session.add(role)
        db.session.flush()
    db.session.commit()


if __name__ == '__main__':
    manager.run()
